package main

import (
	"fmt"
	"regexp"
	"strings"
)

func main() {
	//a := "hello nihao"
	//index := strings.Index(a, "ads")
	//fmt.Println(index)

	//html := "<html><head><title>Test Page</title></head><body><p>Hello, Go!</p></body></html>"
	//
	//fmt.Println(trimHtml(html))

	str := "hello;world;hello;网吧"
	str = strings.Replace(str, ";", "|", -1)
	ix := strings.Index(str, "hello")
	if ix > -1 {
		a := strings.Split(str, "hello")
		fmt.Println(a)
	}

}

func trimHtml(src string) string {
	//将HTML标签全转换成小写
	re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
	src = re.ReplaceAllStringFunc(src, strings.ToLower)
	//去除STYLE
	re, _ = regexp.Compile("\\<style[\\S\\s]+?\\</style\\>")
	src = re.ReplaceAllString(src, "")
	//去除SCRIPT
	re, _ = regexp.Compile("\\<script[\\S\\s]+?\\</script\\>")
	src = re.ReplaceAllString(src, "")
	//去除所有尖括号内的HTML代码，并换成换行符
	re, _ = regexp.Compile("\\<[\\S\\s]+?\\>")
	src = re.ReplaceAllString(src, "\n")
	//去除连续的换行符
	re, _ = regexp.Compile("\\s{2,}")
	src = re.ReplaceAllString(src, "\n")
	return strings.TrimSpace(src)
}
